<template>
    <div class="vmain">
    <loading :loading="loading"></loading>

        <el-container>

            <utabbar :tabactiv="5"></utabbar>
        </el-container>


        <el-main >
            <div class="center">
                <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
                    <el-table-column prop="volunteerColleges" label="院校代号" width="180">
                    </el-table-column>
                    <el-table-column prop="schoolName" label="院校名称" width="180">
                    </el-table-column>
                    <el-table-column prop="volunteering" label="专业代号" width="180">
                    </el-table-column>
                    <el-table-column prop="professionalName" label="专业名称" width="180">
                    </el-table-column>
                <el-table-column fixed="right" label="操作" width="200">
                    <template slot-scope="scope">
                        <el-button @click="getVolunteerInfo(scope.row.volunteerColleges,scope.row.volunteering)" type="primary" size="">查看</el-button>
                        <el-button type="danger" icon="el-icon-delete" @click="delVolunteer(scope.row.id)"></el-button>
                    </template>
                </el-table-column>
                </el-table>


            </div>
        </el-main>


    </div>
</template>
<script>
import utabbar from './fceecomponents/uitabbar.vue'
import tool from './tool/tool'
import axios from 'axios';
import loading from "./fceecomponents/loading.vue"
export default {
    components: {
        utabbar,
        loading
    },
    data() {
        return {
            tableData: '',
            loading:true
        }
    },
    methods: {
        tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      },
        getVolunteer: function () {
            //获取我的支援单
            var that = this
            tool.$request("GET", "/Volunteer/getVolunteer").then(res => {
                console.log(res)
                that.tableData = res.rows;
                that.loading=false
            })
        },
        handleClick(row) {
            console.log(row);
        },
        open() {
      this.$confirm('此功能需要登录使用, 是否继续?', '提示', {
        confirmButtonText: '登录',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
       this.$router.replace('/yonghu')
        this.$message({
          type: 'success',
          message: '即将前往登录界面!',

        });
      }).catch(() => {
        this.$router.replace('/')
        this.$message({
          type: 'info',
          message: '取消'
        });          
      });
    },
    getLogin: function () {
    //   alert("测试")
      axios({
        method: "GET",
        url: "/userInfo",

      }).then(response => {
        // this.UserInfo = response.data.data;
        console.log(response)
        // alert(response.data.code)
        if(response.data.code==1){
          console.log("已登录")
          // alert("未登录")
          this.open()

        }else{
          // this.open4();
          // alert("未登录")
          this.$message({
          showClose: true,
          message: '用户已登录',
          type: 'success'
        });

        }

      })
    },
        delVolunteer(id){
            //删除志愿
            var that = this;
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            // alert(id)
            var url = "/Volunteer/DelVolunteer?id="+id
            tool.$request("POST",url).then(res=>{
                // alert(res.msg)
                location. reload()

                this.$message({
            type: 'success',
            message:res.msg
          });
            })
        
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
      },
      getVolunteerInfo:function(scode,Professional){
            // alert(scode1)
            // alert(ProfessionalCode)
            this.$router.push({
                path:'/schoolinfo',
                name:'schoolinfo',
                params:{
                    scode1s:scode,
                    Prof:Professional
                }
              })

        },

        },
       
    mounted() {
        this.getVolunteer()

    },
    created() {
        this.getLogin()
    }
}

</script>
<style scoped>
.vmain {
    width: 100%;
    height: 100%;
}

.el-table .warning-row {
    background: oldlace;
}

.el-table .success-row {
    background: #f0f9eb;
}
.center{
    margin: 0 auto;
    text-align: center;
}
.el-table{
    margin: 0 auto;
}
</style>